<template>
	<view class="content">
		<z-paging ref="paging" @query='queryList'>
			<template slot='top'>
				<Header :isShowRight="false" title="话题列表" @back='back' arrowColor='#000' textColor='#000' bgColor='#fff'></Header>
			</template>
			<topItem :dataList='dataList' :keyword='search'></topItem>
		</z-paging>
	</view>
</template>

<script>
	import {topicList} from '@/apis/apis.js'
	import Header from '@/components/c_header.vue'
	import topItem from '../modules/topicItem.vue'
	export default{
		components: {
			Header,
			topItem
		},
		data(){
			return {
				search:'',
				dataList:[]
			}
		},
		methods:{
			queryList(pageNo,pageSize){
				topicList({
					pageNum:pageNo,
					pageSize:pageSize,
					search:this.search
				}).then(res=>{
					console.log(res);
					res.data.forEach((el, index) => {
						if (el.workKey) {
							el.words = el.workKey.split(',')
						}
						//置顶
						if(el.topping){
							res.data.unshift(res.data.splice(index , 1)[0]);
						}
					})
					this.dataList=res.data
					this.$refs.paging.complete(res.data)
				})
		    },
			back(){
				uni.navigateBack({
					delta:1
				})
			}
		},
		onLoad(options) {
			console.log(options);
			this.search=options.key
		}
	}
</script>

<style lang='scss' scoped>
	.content{
		width:100%;
		min-height: 100vh;
		background: #f8f8f8;
	}
</style>